/*
	menu screen
*/
#include <hge.h>
#include <hgesprite.h>
#include <hgefont.h>
#include "menu.h"

hgeFont *f_title;
hgeFont *f_menu;
hgeFont *f_text;

HEFFECT snd;

char *menu_string;


bool Menu_Init()
{
	bgtex=hge->Texture_Load("resources/images/background.png");
	snd=hge->Effect_Load("resources/sounds/menuchoice.wav");
	f_title=new hgeFont("resources/fonts/title.fnt");
	f_menu=new hgeFont("resources/fonts/heading.fnt");
	f_text=new hgeFont("resources/fonts/text.fnt");
	if (!bgtex|!f_title|!f_menu|!f_text) return false;

	bgspr=new hgeSprite(bgtex,0,0,800,600);
	bgspr->SetBlendMode(BLEND_COLORMUL| BLEND_ALPHABLEND | BLEND_NOZWRITE);
	bgspr->SetColor(0xFFDDDDDD);

	return true;
}

bool Menu_Clean()
{
	delete bgspr;
	hge->Effect_Free(snd);
	hge->Texture_Free(bgtex);
	delete f_title;
	delete f_menu;
	delete f_text;
	return true;
}

bool Menu_Frame()
{

	if ((hge->Input_KeyDown(HGEK_P))){
		hge->Effect_Play(snd);
		menu_string = "GOGOGOGOGO!";
		Menu_Clean();
		Play_Init();
		hge->System_SetState(HGE_FRAMEFUNC, Play_Frame);
		hge->System_SetState(HGE_RENDERFUNC, Play_Render);
		return false;
	}
	if ((hge->Input_KeyDown(HGEK_I))){
		hge->Effect_Play(snd);
		menu_string = "Right arrow: Clockwise\nLeft arrow: Counter-clockwise\nUp arrow: Move ball up\nDown arrow: Move ball down\nCTRL: Shoot ball\n\nHit the orange block to win!";
	}
	if ((hge->Input_KeyDown(HGEK_C))){
		hge->Effect_Play(snd);
		menu_string = "Programming:\nGreg '\%s' Joyce\nScott 'Cash Money' Faria\nDesign:\nGreg 'Greggles' Joyce\nScott 'NICKNAMEGOESHERE' Faria\nHeidi Harribine\nJustin Clark";
	}
	if ((hge->Input_KeyDown(HGEK_E))){
		hge->Effect_Play(snd);
		menu_string = "LATER!";
		Menu_Clean();
		return true;
	}

	return false;
}

bool Menu_Render()
{
	hge->Gfx_BeginScene();
	hge->Gfx_Clear(0);
	bgspr->Render(0,0);
	f_title->printf(125, 100, HGETEXT_LEFT, "C R A Z Y   B A L L :");
	f_text->printf(150, 150, HGETEXT_LEFT,"square conflict\n \\\\alpha remix.[final_cut]\n\n");
	f_menu->printf(250, 250, HGETEXT_LEFT,"[P]lay\n[I]nstructions\n[C]redits\n[E]xit\n\n");
	f_text->printf(100, 400, HGETEXT_LEFT,"%s", menu_string);
	hge->Gfx_EndScene();

	return false;
}
